package app;

import Thanh.EmployeeManage;
import holidaysManager.HolidaysManagerDefault;
import java.awt.Color;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import patientManager.PatientTab;
import profiles.ProfilesDefault;
import requestManager.RequestManagerDefault;
import scheduleManager.ScheduleManagerAssignEmployee;
import scheduleManager.ScheduleManagerAssignHead;
import scheduleManager.ScheduleManagerDefault;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Home.java
 *
 * Created on Aug 11, 2011, 4:08:46 PM
 */
/**
 *
 * @author Fun
 */
public class Home extends javax.swing.JFrame {

    /** Creates new form Home */
    public Home() {
        initComponents();
        initMyComponents();
        this.getContentPane().setBackground(Color.WHITE);
        this.setSize(1000, 700);
        this.setResizable(false);
    }

    private void initMyComponents() {
        lblAuth.setText("Welcome, " + Global.getAuth().getUsername());
        lblRoll.setText(Global.getAuth().getRollName());
        lblDepartment.setText(Global.getAuth().getDepartment().getName());
    }

    public void load(JPanel panel) {
        middleContent.removeAll();
        panel.setSize(880, 500);
        middleContent.add(panel, java.awt.BorderLayout.CENTER);
        this.validate();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        containerPanel = new javax.swing.JPanel();
        topPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        lblAuth = new javax.swing.JLabel();
        lblRoll = new javax.swing.JLabel();
        lblDepartment = new javax.swing.JLabel();
        btnLogout = new javax.swing.JButton();
        leftPanel = new javax.swing.JPanel();
        btnProfile = new javax.swing.JButton();
        btnSchedule = new javax.swing.JButton();
        btnRequest = new javax.swing.JButton();
        btnAssign = new javax.swing.JButton();
        btnHolidays = new javax.swing.JButton();
        btnDepartments = new javax.swing.JButton();
        btnEmployees = new javax.swing.JButton();
        btnPatients = new javax.swing.JButton();
        btnAboutUs = new javax.swing.JButton();
        middleContent = new javax.swing.JPanel();
        contentPanel = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        containerPanel.setPreferredSize(new java.awt.Dimension(550, 416));
        containerPanel.setLayout(new java.awt.BorderLayout());

        topPanel.setPreferredSize(new java.awt.Dimension(1413, 193));
        topPanel.setLayout(new java.awt.BorderLayout());

        jPanel1.setPreferredSize(new java.awt.Dimension(739, 193));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/banner.jpg"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 193, Short.MAX_VALUE)
        );

        topPanel.add(jPanel1, java.awt.BorderLayout.LINE_START);

        jPanel2.setBackground(java.awt.Color.white);
        jPanel2.setFont(new java.awt.Font("Verdana", 0, 15));

        lblAuth.setFont(new java.awt.Font("Verdana", 0, 15));
        lblAuth.setText("jLabel2");

        lblRoll.setText("jLabel2");

        lblDepartment.setText("jLabel2");

        btnLogout.setText("Logout");
        btnLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLogoutActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDepartment)
                    .addComponent(lblRoll)
                    .addComponent(lblAuth)
                    .addComponent(btnLogout, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(357, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(lblAuth)
                .addGap(18, 18, 18)
                .addComponent(lblRoll)
                .addGap(18, 18, 18)
                .addComponent(lblDepartment)
                .addGap(18, 18, 18)
                .addComponent(btnLogout)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        topPanel.add(jPanel2, java.awt.BorderLayout.CENTER);

        containerPanel.add(topPanel, java.awt.BorderLayout.PAGE_START);

        leftPanel.setBackground(java.awt.SystemColor.controlLtHighlight);
        leftPanel.setPreferredSize(new java.awt.Dimension(130, 395));
        leftPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 5, 10));

        btnProfile.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Profiles.png"))); // NOI18N
        btnProfile.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnProfile.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnProfile.setPreferredSize(new java.awt.Dimension(120, 20));
        btnProfile.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/ProfilesHover.png"))); // NOI18N
        btnProfile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProfileActionPerformed(evt);
            }
        });
        leftPanel.add(btnProfile);

        btnSchedule.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Schedules.png"))); // NOI18N
        btnSchedule.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnSchedule.setPreferredSize(new java.awt.Dimension(120, 20));
        btnSchedule.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/SchedulesHover.png"))); // NOI18N
        btnSchedule.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnScheduleActionPerformed(evt);
            }
        });
        leftPanel.add(btnSchedule);

        btnRequest.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Requests.png"))); // NOI18N
        btnRequest.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnRequest.setPreferredSize(new java.awt.Dimension(120, 20));
        btnRequest.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/RequestHover.png"))); // NOI18N
        btnRequest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRequestActionPerformed(evt);
            }
        });
        leftPanel.add(btnRequest);

        btnAssign.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Assign.png"))); // NOI18N
        btnAssign.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnAssign.setPreferredSize(new java.awt.Dimension(120, 20));
        btnAssign.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/AssignHover.png"))); // NOI18N
        btnAssign.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAssignActionPerformed(evt);
            }
        });
        leftPanel.add(btnAssign);

        btnHolidays.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/holidays.png"))); // NOI18N
        btnHolidays.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnHolidays.setPreferredSize(new java.awt.Dimension(120, 20));
        btnHolidays.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/HolidaysHover.png"))); // NOI18N
        btnHolidays.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHolidaysActionPerformed(evt);
            }
        });
        leftPanel.add(btnHolidays);

        btnDepartments.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/deparments.png"))); // NOI18N
        btnDepartments.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnDepartments.setPreferredSize(new java.awt.Dimension(120, 20));
        btnDepartments.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/DepartmentsHover.png"))); // NOI18N
        btnDepartments.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDepartmentsActionPerformed(evt);
            }
        });
        leftPanel.add(btnDepartments);

        btnEmployees.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Employee.png"))); // NOI18N
        btnEmployees.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnEmployees.setPreferredSize(new java.awt.Dimension(120, 20));
        btnEmployees.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/EmployeeHover.png"))); // NOI18N
        btnEmployees.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEmployeesActionPerformed(evt);
            }
        });
        leftPanel.add(btnEmployees);

        btnPatients.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Patients.png"))); // NOI18N
        btnPatients.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnPatients.setPreferredSize(new java.awt.Dimension(120, 20));
        btnPatients.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/PatientsHover.png"))); // NOI18N
        btnPatients.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPatientsActionPerformed(evt);
            }
        });
        leftPanel.add(btnPatients);

        btnAboutUs.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/AboutUs.png"))); // NOI18N
        btnAboutUs.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btnAboutUs.setPreferredSize(new java.awt.Dimension(120, 20));
        btnAboutUs.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/img/AboutUsHover.png"))); // NOI18N
        btnAboutUs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAboutUsActionPerformed(evt);
            }
        });
        leftPanel.add(btnAboutUs);

        containerPanel.add(leftPanel, java.awt.BorderLayout.LINE_START);

        middleContent.setLayout(new java.awt.BorderLayout());

        contentPanel.setFont(new java.awt.Font("Verdana", 0, 15));
        contentPanel.setLayout(new java.awt.BorderLayout());
        middleContent.add(contentPanel, java.awt.BorderLayout.CENTER);

        containerPanel.add(middleContent, java.awt.BorderLayout.CENTER);

        getContentPane().add(containerPanel, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProfileActionPerformed
    this.load(new ProfilesDefault());
}//GEN-LAST:event_btnProfileActionPerformed

private void btnRequestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRequestActionPerformed
    if (Global.getAuth().isManager()) {
        this.load(new RequestManagerDefault(1));
    } else {
        this.load(new RequestManagerDefault(Global.getAuth().getDepartmentId()));
    }
}//GEN-LAST:event_btnRequestActionPerformed

private void btnScheduleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnScheduleActionPerformed
    if (Global.getAuth().isManager()) {
        this.load(new ScheduleManagerDefault(1));
    } else {
        this.load(new ScheduleManagerDefault(Global.getAuth().getDepartmentId()));
    }
}//GEN-LAST:event_btnScheduleActionPerformed

private void btnAssignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAssignActionPerformed
    if (Global.getAuth().isManager()) {
        this.load(new ScheduleManagerAssignHead(1));
    } else if (Global.getAuth().isDepartmentHead()) {
        this.load(new ScheduleManagerAssignEmployee(Global.getAuth().getDepartmentId()));
    } else {
        JOptionPane.showMessageDialog(Global.getFrame(), "You can not access here", "Permission Deny", JOptionPane.ERROR_MESSAGE);
    }

}//GEN-LAST:event_btnAssignActionPerformed

private void btnHolidaysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHolidaysActionPerformed
    this.load(new HolidaysManagerDefault());
}//GEN-LAST:event_btnHolidaysActionPerformed

private void btnDepartmentsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDepartmentsActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btnDepartmentsActionPerformed

private void btnPatientsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPatientsActionPerformed
    this.load(new PatientTab().getPanel());
}//GEN-LAST:event_btnPatientsActionPerformed

private void btnAboutUsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutUsActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btnAboutUsActionPerformed

private void btnLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogoutActionPerformed
    if (JOptionPane.showConfirmDialog(Global.getFrame(), "Are you sure to logout?", "Logout confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
        this.dispose();
        new Login().setVisible(true);
    }
}//GEN-LAST:event_btnLogoutActionPerformed

private void btnEmployeesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmployeesActionPerformed
    this.load(new EmployeeManage());
}//GEN-LAST:event_btnEmployeesActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAboutUs;
    private javax.swing.JButton btnAssign;
    private javax.swing.JButton btnDepartments;
    private javax.swing.JButton btnEmployees;
    private javax.swing.JButton btnHolidays;
    private javax.swing.JButton btnLogout;
    private javax.swing.JButton btnPatients;
    private javax.swing.JButton btnProfile;
    private javax.swing.JButton btnRequest;
    private javax.swing.JButton btnSchedule;
    private javax.swing.JPanel containerPanel;
    private javax.swing.JPanel contentPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lblAuth;
    private javax.swing.JLabel lblDepartment;
    private javax.swing.JLabel lblRoll;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JPanel middleContent;
    private javax.swing.JPanel topPanel;
    // End of variables declaration//GEN-END:variables
}
